json = require("json")
nett = io.popen("cat /proc/net/dev")
local t = {}
for line in nett:lines() do
	local _, _, interface, 
	rxbytes, rxpackets, rxerrs, rxdrop, rxfifo, rxframe, rxcompressed, rxmulticast,
	txbytes, txpackets, txerrs, txdrop, txfifo, txframe, txcompressed, txmulticast = string.find(line, 
	"(%S+):%s*(%d+)%s*(%d+)%s*(%d+)%s*(%d+)%s*(%d+)%s*(%d)%s*(%d+)%s*(%d+)%s*(%d+)%s*(%d+)%s*(%d+)%s*(%d+)%s*(%d+)%s*(%d)%s*(%d+)%s*(%d+)")
	if interface then
--		print(interface, 
--				rxbytes, rxpackets, rxerrs, rxdrop, rxfifo, rxframe, rxcompressed, rxmulticast,
--				txbytes, txpackets, txerrs, txdrop, txfifo, txframe, txcompressed, txmulticast)
--		print(interface, rxbytes, txbytes)
		t[interface] = {}
		t[interface].rx ={}
		t[interface].rx.bytes = rxbytes
		t[interface].rx.packets = rxpackets
		t[interface].rx.errs = rxerrs
		t[interface].rx.drop = rxdrop
		t[interface].rx.info = rxfifo
		t[interface].rx.frame = rxframe
		t[interface].rx.compressed = rxcompressed
		t[interface].rx.multicast = rxmulticast
		t[interface].tx ={}
		t[interface].tx.bytes = txbytes
		t[interface].tx.packets = txpackets
		t[interface].tx.errs = txerrs
		t[interface].tx.drop = txdrop
		t[interface].tx.info = txfifo
		t[interface].tx.frame = txframe
		t[interface].tx.compressed = txcompressed
		t[interface].tx.multicast = txmulticast
	end
end	
nett:close()
print(json.encode(t))
